#include "ReaderWriterMgr.h"
#include <algorithm>
#include "FileHelper.h"

#include "NezhaCFileSystem.h"
#include "NezhaIFileSystem.h"

#ifdef WIN32
#pragma comment(lib, "NezhaEngine_d.lib")
#endif // WIN32

namespace Nezha
{
	namespace stream
	{
		IFileSystem* getGlobalFileSystem()
		{
			if(!IFileSystem::GetInterface())
			{
				// no custom file system setup yet, create default version.
				IFileSystem::SetGlobalFileSystem(NZ_New CFileSystem());
			}
			return IFileSystem::GetInterface();
		}
	}

	void ReaderWriterMgr::regeditExt(const std::string& ext)
	{
		if (!supportExt(ext))
		{
			mSupportExt.push_back(mCaseSentive? ext : getSensitiveString(ext, lower));
		}
	}

	bool ReaderWriterMgr::supportFile(const std::string& fileName) const
	{
		return supportExt(getFileExtension(fileName));
	}
	bool ReaderWriterMgr::supportExt(const std::string& ext) const
	{
		if (mCaseSentive)
		{
			return std::find(mSupportExt.begin(), mSupportExt.end(), ext) != mSupportExt.end();
		}
		else
		{
			return std::find(mSupportExt.begin(), mSupportExt.end(), getSensitiveString(ext, lower))
				!= mSupportExt.end();
		}
	}

}